Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser,css_parser): implement checkpoint rewinding #1417

Merged
merged 3 commits into from
Jan 3, 2024

Conversation

faultyserver
Copy link
Contributor

Summary

From #268 (comment), this implements checkpoint rewinding for the CSS parser to set up for attempting to parse property values and then falling back to generics if the parse fails for any reason.

I think there's another possibility of using rewrite_events the way that the JsParser does to avoid the need for rewinding, but I think it's actually okay to just rewind since there's little cost to it, and we aren't enforcing a particular structure on the re-parsed content (it could be either GenericComponentValueList or Bogus, we don't actually know at the point of rewinding).

Test Plan

Added a test around try_parse to ensure it rewinds as expected on error and preserves the position on success. Future PRs will start actually using it in the parser logic itself.

Copy link

netlify bot commented Jan 3, 2024

Deploy Preview for biomejs canceled.

Name Link
🔨 Latest commit 6a54966
🔍 Latest deploy log https://app.netlify.com/sites/biomejs/deploys/6595dd7dfa373d0008cb7b70

@github-actions github-actions bot added A-Parser Area: parser L-JavaScript Language: JavaScript and super languages L-CSS Language: CSS labels Jan 3, 2024
Copy link
Contributor

github-actions bot commented Jan 3, 2024

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 49701 49701 0
Passed 48721 48721 0
Failed 980 980 0
Panics 0 0 0
Coverage 98.03% 98.03% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6322 6322 0
Passed 2036 2036 0
Failed 4286 4286 0
Panics 0 0 0
Coverage 32.20% 32.20% 0.00%

ts/babel

Test result main count This PR count Difference
Total 662 662 0
Passed 592 592 0
Failed 70 70 0
Panics 0 0 0
Coverage 89.43% 89.43% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 17646 17646 0
Passed 13452 13452 0
Failed 4192 4192 0
Panics 2 2 0
Coverage 76.23% 76.23% 0.00%

p: &mut CssParser,
func: impl FnOnce(&mut CssParser) -> Result<T, E>,
) -> Result<T, E> {
let checkpoint = p.checkpoint();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to implement speculative_parsing?
It blocks a parse recovery since we're going to rewind anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it's probably best that we do just for safety. I don't think we need it strictly for how it'll be used here, but definitely no harm in including it. I'll add it in now.

Copy link
Contributor

@denbezrukov denbezrukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉🎉🎉

Copy link

codspeed-hq bot commented Jan 3, 2024

CodSpeed Performance Report

Merging #1417 will not alter performance

⚠️ No base runs were found

Falling back to comparing faulty/css-parser-checkpoint (6a54966) with main (3c24e4c)

Summary

✅ 93 untouched benchmarks

@faultyserver faultyserver force-pushed the faulty/css-parser-checkpoint branch from 273627f to 433c4dd Compare January 3, 2024 21:42
@faultyserver faultyserver merged commit 9f46988 into main Jan 3, 2024
20 checks passed
@faultyserver faultyserver deleted the faulty/css-parser-checkpoint branch January 3, 2024 22:54
@Conaclos Conaclos added the A-Changelog Area: changelog label Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Parser Area: parser L-CSS Language: CSS L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants